<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Set extends Model
{
	protected $primaryKey = 'name';
	
	protected $table = 'set';
    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = ['name','data'];

    /**
     * 是否主动维护时间戳
     *
     * @var bool
     */
    public $timestamps = false;
    
    public static function getSets($name = 'system'){
    	$set = (new Set())->select('data')->where('name',$name)->first();
    	if (empty($set)) return [];
    	return unserialize($set->data);
    }
    
    public static function setSets($data,$name = 'system'){
    	$sm = new Set();
    	$set = $sm->select('name')->where('name',$name)->first();
    	if (empty($set)){
    		$sm->name = $name;
    		$sm->data = serialize($data);
    		$sm->save();
    	}else{
    		$set->data = serialize($data);
    		$set->save();
    	}
    }
}
